using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Collections;
public class UpCardBagSystem : Singleton<UpCardBagSystem>, IBagSystem
{
    public List<BagItemData> dataList { get; private set; }
    public List<IBagItemView> viewList { get; private set; }
    public IBagItemView selectedView { get; set; }
    void OnEnable()
    {
        ActionSystem.AttachPerformer<BagSelectedGA>(BagSelectedPerformer);
    }

    void OnDisable()
    {
        ActionSystem.DetachPerformer<BagSelectedGA>();
    }
    IEnumerator BagSelectedPerformer(BagSelectedGA bagSelectedGA)
    {
        if (viewList.Contains(bagSelectedGA.View))
        {
            foreach (var view in viewList)
            {
                view.IsHighlighted = false;
            }
            bagSelectedGA.View.IsHighlighted = true;
            selectedView = bagSelectedGA.View;
            yield return null;
        }
    }

    [SerializeField] private Bag BagPrefab;
    [SerializeField] private GameObject Slot;
    private Bag bag;
    public void Setup()
    {
        dataList = InfoSystem.Instance.hero.Cards.ToList<BagItemData>();
        bag = Instantiate(BagPrefab, Slot.transform);
        bag.Setup(dataList);
        viewList = bag.GetViews();
    }
    public void UpCard()
    {
           
        if (selectedView is CardView cardView)
        {
            Debug.Log("升级");
            cardView.card.ProNumber = 1;
            cardView.Refresh();
        }
     
    }
    public void Close()
    {
        bag.gameObject.SetActive(false);
        Destroy(bag.gameObject);
    }





    System.Collections.IEnumerator IBagSystem.BagSelectedPerformer(BagSelectedGA bagSelectedGA)
    {
        throw new System.NotImplementedException();
    }


}

